package com.example.yls.demoa;

/**
 * Created by yls on 2018/10/22.
 */
import android.content.Context;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.View;
import  java.util.ArrayList;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
class StuAdapter extends RecyclerView.Adapter<StuViewHolder>{
    private Context context;
    private ArrayList<Student> studentArrayList;

    public StuAdapter(Context context, ArrayList<Student> studentArrayList) {
        this.context = context;
        this.studentArrayList = studentArrayList;
    }


    @Override
    public int getItemCount() {
        return studentArrayList.size();
    }

    @Override
    public StuViewHolder onCreateViewHolder(ViewGroup parent,int viewType){
        View view = LayoutInflater.from(context).inflate(
                R.layout.list_item, parent, false);

        StuViewHolder viewHolder = new StuViewHolder(view);
        return viewHolder;
    }
    @Override
    public void onBindViewHolder(StuViewHolder holder, int position) {
        Student s = studentArrayList.get(position);

      holder.headView.setImageResource(s.getImgId());
      holder.nameView.setText(s.getName());
      holder.ageView.setText(String.valueOf(s.getAge()));

    }



}

